
cc.Class({
    extends: cc.Component,

    properties: {
        jumps: 2,
        jumpSpeed: 200,
        roleNode: cc.Node,
    },

    // use this for initialization
    onLoad: function () {
 
        this._up = false;
        
        this.body = this.node.getComponent(cc.RigidBody);

        this._Animation = this.roleNode.children[0].getComponent(cc.Animation);
    },

    onDown () {
        if (!this._upPressed) {
            this._up = true;
            //this._Animation.stop();
        }
        this._upPressed = true;
    },

    onUp () {
        this._upPressed = false;
    },


    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        var speed = this.body.linearVelocity;

        if(Math.abs(speed.y) < 1 ) {
            this.jumps  = 2;

        }

        if (this.jumps > 0 && this._up) {
            speed.y = this.jumpSpeed;
            this.jumps -= 1 ;
            console.error(this.jumps);

        }

        this._up = false;
        this.body.linearVelocity = speed;
    },
});
